package com.sc.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sc.bean.T_seal;
import com.sc.bean.T_waiting;
import com.sc.bean.User;
import com.sc.serviceimpl.ApproverImpl;
import com.sc.serviceimpl.SealServiceImpl;
import com.sc.serviceimpl.WaitingServiceImpl;


@Controller
public class SealController {

	@Autowired
	private WaitingServiceImpl waiServiceImpl;
	
	@Autowired
	private ApproverImpl approverImpl;
	
	@Autowired
	private SealServiceImpl sealServiceImpl;
	
	@RequestMapping("addseal")
	public String addseal(HttpServletRequest  request,Model model){
		String fan="";
		T_seal seal=new T_seal();
		seal.setS_approver(request.getParameter("approver"));
		seal.setS_day(request.getParameter("day"));
		seal.setS_dept(request.getParameter("dept"));	
		seal.setS_lei(request.getParameter("lei"));
		seal.setS_cause(request.getParameter("cause"));
		seal.setS_uname(request.getParameter("uname"));
		
		int i = sealServiceImpl.add(seal);
		
		List<User> userList=approverImpl.find();
		
		model.addAttribute("userList",userList);
		model.addAttribute("str", 222);
		String result="";
		
		if(i!=1){
			result="申请失败";
			fan="addSeal";
			System.out.println( "申请失败");
		}else{						
			System.out.println( "申请成功");
			T_waiting wai=new T_waiting();
			wai.setWt_pname(request.getParameter("uname"));
			wai.setWt_tname(request.getParameter("uname")+"用章申请");
			wai.setWt_status("未审核");
			wai.setWt_starttime(request.getParameter("day"));
			wai.setWt_table("t_seal");
			int a = waiServiceImpl.add(wai);

			if(a!=1){	
				System.out.println("添加审核失败");
			}else{
				fan="waiting";
				System.out.println("添加审核成功");
			}
		}
		model.addAttribute("result",result);
		return fan;
	}

	
	
	
	
}
